﻿@{
    ViewBag.Title = " 广告位列表";
    Layout = "~/Areas/Shared/_spListV1.cshtml";
    ViewBag.ListActionURL = Url.Action("ListAdvertSpace", "AdvertManage", new { area = "Cubic" });
    ViewBag.AddActionURL = Url.Action("EditAdvertSpace", "AdvertManage", new { area = "Cubic" });
    ViewBag.DelActionURL = Url.Action("DelListAdvertSpace", "AdvertManage", new { area = "Cubic" });
    ViewBag.EditActionURL = Url.Action("EditAdvertSpace", "AdvertManage", new { area = "Cubic" });
    ViewBag.ShowAdvertURL = Url.Action("ListAdvert", "AdvertManage", new { area = "Cubic" });
    ViewBag.IdColumn = "Id";
    ViewBag.NameColumn = "Title";
    ViewBag.ListSortName = "";
    ViewBag.ListSortOrder = "";
    ViewBag.AddWindowTitle = "添加广告位";
    ViewBag.EditWindowTitle = "编辑广告位";   
}


@model Kaiser.Modules.Cubic.DomainModel.Product.ProductDetail
@section Script
{
    <script type="text/javascript">

        config.GridOption.toolbar = "#tb";
        config.GridOption.columns = [[
            { field: 'Code', title: 'Code', width: 50, sortable: true },
            {
                field: 'Title', title: '标题', width: 50, sortable: true, formatter: function (value, row, index) {
                    var html = "<a id='ViewAdvertList' href='#'>" + value + "</a>";
                    return html;
                }
            },
            { field: 'Template', title: '模版', width: 150, sortable: true },
            { field: 'Remark', title: '备注', width: 20, sortable: true },
            {
                field: '操作',
                title: '操作',
                width: 60,
                formatter: function (value, row, rowIndex) {
                    var arr = new Array();

                    arr.push('<a href=# class="OpertaionButton"  onclick=ShowAdvert("' + rowIndex + '")>[广告列表]</a>');
                    arr.push('<a href=# class="OpertaionButton"  onclick=EditItem("' + rowIndex + '")>[修改]</a>');
                    arr.push('<a href=# class="OpertaionButton"  onclick=del("' + row.Id + '")>[删除]</a>');
                    return arr.join('');
                }
            }

        ]];

        config.GridOption.onClickCell = function (rowIndex, field, value) {

            var data = $('#grid').datagrid('getData');

            if (field == 'Title') {

                dialog = parent.openWindow({
                    title: "编辑广告栏位",
                    url: '@Url.Action("EditAdvertSpace")?id=' + data.rows[rowIndex].Id,
                    height: 600,
                    width: 800,
                    isIframe: true,
                    maximizable: true,
                    toolbar:[
                 {
                     text:'保存',
                     iconCls:"icon-save",
                     handler:function() {
                         dialog.find("iframe")[0].contentWindow.saveData(function(f) {
                             if (f) {
                                 dialog.dialog("close");
                                 grid.datagrid('reload');
                             }
                         });
                     }
                 },   
                 {
                     text:'关闭',
                     iconCls:"icon-no",
                     handler:function() {
                         dialog.dialog("close");
                     }
                 }
                    ]
                });


            }
        };
    </script>
}
<div id="tb">
    <div>
        <div style="float: left">
            <a href="#" class="easyui-linkbutton" style="margin-top: 4px" iconcls="icon-add" plain="true">新增</a>
        </div>
        <div style="float: left">
            <form method="post" id="QuickSearch" class="quickSearch">
                <table>
                    <tr>
                        <td>广告位标题： @Html.TextBox("Title")
                            @Html.Hidden("Id")
                        </td>
                        <td>
                            <a href="#" class="easyui-linkbutton" iconcls="icon-search" onclick="Search()">查询</a>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
        <div style="clear: left"></div>
    </div>
    <div style="margin-bottom: 5px">
    </div>
</div>

<script type="text/javascript">
    var categoryId = '';
    function Search() {
        var sf = $("#QuickSearch").serializeJson();
        //alert(sf);
        grid.datagrid({ url: virpath + config.ListActionURL, queryParams: sf });
    }
    $("#QuickSearch input").keyup(function (event) {
        if (event.keyCode == 13) Search();
    });

    $(function () {
        document.ShowAdvert = function(rowIndex) {
            var rows = grid.datagrid('getRows');
            var row = rows[rowIndex];
            var url = '@Url.Action("ListAdvert", "AdvertManage", new { area = "Cubic" })';
            url += '?id=' + row.@ViewBag.IdColumn;

            dialog = parent.openWindow({
                title: "广告管理",
                url: url,
                height: 600,
                width: 800,
                isIframe: true,
                maximizable: true,                
            });
        };
    });

    

    function createColumnMenu() {
        var tmenu = $('<div id="tmenu" style="width:100px;"></div>').appendTo('body');
        var fields = grid.datagrid('getColumnFields');
        for (var i = 0; i < fields.length; i++) {
            $('<div iconCls="icon-ok"/>').html(fields[i]).appendTo(tmenu);
        }
        tmenu.menu({
            onClick: function (item) {
                if (item.iconCls == 'icon-ok') {
                    grid.datagrid('hideColumn', item.text);
                    tmenu.menu('setIcon', {
                        target: item.target,
                        iconCls: 'icon-empty'
                    });
                } else {
                    grid.datagrid('showColumn', item.text);
                    tmenu.menu('setIcon', {
                        target: item.target,
                        iconCls: 'icon-ok'
                    });
                }
            }
        });
    }

    function getSelectedArr() {
        var ids = [];
        var rows = grid.datagrid('getSelections');
        for (var i = 0; i < rows.length; i++) {
            ids.push(rows[i].BookID);
        }
        return ids;
    }
    function getSelectedID() {
        var ids = getSelectedArr();
        return ids.join(',');
    }
    function arr2str(arr) {
        return arr.join(',');
    }
</script>
